<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <div class="app-upload-item">
            安装包：
            <input @change="handleFileInpueChange" type="file" name="">
        </div>
        <div class="app-upload-item">
            系统：
            <select v-model="uploadInfo.system" name="">
                <option value="IOS" selected>IOS</option>
                <option value="Android">Android</option>
            </select>
        </div>
        <div class="app-upload-item">
            版本更新信息：
            <input v-model="uploadInfo.message" type="text">
        </div>
        <div class="app-upload-item">
            是否强制更新：
            <select v-model="uploadInfo.updateForce" name="">
                <option value="0" selected>否</option>
                <option value="1">是</option>
            </select>
        </div>
        <div class="app-upload-item">
            <button @click="uploadApp">上传</button>
        </div>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.16/vue.min.js"></script>
    <script>
        new Vue({
            el: "#app",
            data: {
                uploadInfo: {
                    updateDate: "",
                    updateForce: 0,
                    system: "Android",
                    versionInfo: null,
                    message: ""
                }
            },
            methods: {
                uploadApp() {
                    const {
                        uploadInfo
                    } = this;

                    if (!uploadInfo.versionInfo) {
                        return alert('请上传文件');
                    }
                    // 把数据放进formdata里面
                    var formdata = new FormData();
                    for (var key in uploadInfo) {
                        var value = uploadInfo[key];
                        formdata.append(key, value)
                    }
                    // 使用axios上传文件
                    axios({
                        url: '/neverlostAdmin/admin/addApk.action',
                        method: 'post',
                        data: formdata,
                        headers: {
                            // 如果不正确就修改
                            'Content-Type': 'multipart/form-data'
                        }
                    }).then((res) => {
                        console.log(res)
                    })
                    
                },

                handleFileInpueChange(event) {
                    this.uploadInfo.versionInfo = event.target.files[0]
                }
            }
        })
    </script>
</body>

</html>